Devices > Remote Devices > Device Template Files > Reference Methods > Time Formatting Examples

Time Formatting Examples

This topic provides numerous useful examples of the various ways you can use reference methods in your device template files to perform conversions with constant values and/or reference data group element values. A sample device template file using each example is available upon request; it can be loaded to a DDS and used to test your reference methods. It is called ReferenceTester.dtf. See also Conversion Methods.

The following table lists and describes available human-readable date and time formats.

Method Format Example
Duration d hh:mm:ss 1 01:24:15
DateTime dd-MMM-yy hh:mm:ss 29-Dec-11 06:00:00
Date dd-MMM-yy 29-Dec-11
Time hh:mm:ss 06:00:00
CygDateTime Days since midnight 12/30/1899. 40906.25
General Date MM/dd/yyyy hh:mm:ss AM/PM 12/29/2011 6:00:00 AM
Long Date Day of Week, Month dd, yyyy Thursday, December 29, 2011
Medium Date dd-MMM-yy 29-Dec-11
Short Date MM/dd/yyyy 12/29/2011
Long Time hh:mm:ss AM/PM 6:00:00 AM
Medium Time hh:mm AM/PM 06:00 AM
Short Time hh:mm 06:00
MMM dd yyyy hh:mm:ss MMM dd yyyy hh:mm:ss Dec 29 2011 06:00:00

See the following subsections for details:

For information about example data group elements and values used below, see Example Values.

3-Byte Date/Time

The following example uses two child elements to convert a date and time from 3-byte date and time formats into the DateTime format.The first child element references the operation opTime3Byte and the data group elements rawDate3 and rawTime3 to assign current values. The second child element then references the operation opFormat to output a date and time in DateTime format. In this case, the 3-byte date (integer 859907) and time (integer 726285) values initialized for this data group result in a date of 31-Mar-13 13:21:11. This date-time representation is used by Thermo SuperFlo II devices.

<Dt3Byte desc="Date Time 3Byte" readOnly="true" type="string" isRef="1">

<ref prec="0" refOp="opTime3Byte" deidDate="rawDate3" deidTime="rawTime3"/>

<ref prec="1" refOp="opFormat" format="DateTime"/>

</Dt3Byte>

Useful attributes to know are isRef, prec, refOp, deidDate, deidTime, and format. A useful element to know is ref.

Component Date/Time

The following example uses two child elements to convert a date and time from several date and time components. The first child element references the operation opTimeComp and the data group elements rawYear, rawMon, rawDay, rawHour, rawMin, and rawSec to assign current values. The second child element then references the operation opFormat to output a date and time in DateTime format. In this case, a value of 13-Apr-12 13:45:17 is produced when the referenced data group elements have these values: deidYear = 2012, deidMonth = 4, deidDay = 13, deidHour = 13, deidMinute = 45, and deidSecond = 17.

<DtComp desc="Date Time Component" readOnly="true" type="string" isRef="1">

<ref prec="0" refOp="opTimeComp" deidYear="rawYear" deidMonth="rawMon" deidDay="rawDay" deidHour="rawHour" deidMinute="rawMin" deidSecond="rawSec"/>

<ref prec="1" refOp="opFormat" format="DateTime"/>

</DtComp>

Useful attributes to know are isRef, prec, refOp, deidYear, deidMonth, deidDay, deidHour, deidMinute, deidSecond, and format. A useful element to know is ref.

Date/Time Format (A)

The following example references the data group element rawTm and converts the value from days since midnight 12/30/1899 to the DateTime format. The result is 29-Dec-11 06:00:00 because 40906.25 is converted to the DateTime format.

<FmtDtA desc="Format Date/Time Method A" readOnly="true" type="string" ref="rawTm" format="DateTime"/>

Useful attributes to know are ref and format.

Date/Time Format (B)

The following example uses two child elements to compute a date/time. The first child element references the operation opAssignId and the data group element rawTm to assign the current value of rawTm as the initial value for FmtDtB. The second child element references the operation opFormat to apply the DateTime format to the value assigned by the first child element. The result is 29-Dec-11 06:00:00 because 40906.25 is converted to the DateTime format.

<FmtDtB desc="Format Date/Time Method B" readOnly="true" type="string" isRef="1">

<ref prec="0" refOp="opAssignId" deid="rawTm"/>

<ref prec="1" refOp="opFormat" format="DateTime"/>

</FmtDtB>

Useful attributes to know are isRef, prec, refOp, deid, and format. A useful element to know is ref.

Date/Time Format (C)

The following example uses one child element to compute a date/time. The child element references the operation opFormatId and the data group element rawTm to assign the current value of rawTm as the initial value for FmtDtIdC. The DateTime format is then applied to the current value of rawTm. The result is 29-Dec-11 06:00:00 because 40906.25 is converted to the DateTime format.

<FmtDtIdC desc="Format DateTime by DEID Method C" readOnly="true" type="string" isRef="1">

<ref prec="0" refOp="opFormatId" deid="rawTm" format="DateTime"/>

</FmtDtIdC>

Useful attributes to know are isRef, prec, refOp, deid, and format. A useful element to know is ref.

Duration Format (A)

The following example references the data group element rawDur and converts the value from seconds to the Duration format. In the referenced data group element (in this case, rawDur), you must use the units attribute to define the referenced data group element's units as seconds. For example, you would include units="sec" inline in the referenced data group element so that the conversion method could properly interpret its input value as seconds. The result is 00:24:15 because 1455 is converted to the Duration format.

<FmtDurA desc="Format Duration Method A" readOnly="true" type="string" ref="rawDur" format="Duration"/>

Useful attributes to know are units, ref, and format.

Duration Format (B)

The following example uses the opAssignId operator to reference the data group element rawDur, and it uses the opUnitConversion reference operator to convert the assigned value from seconds to decimal days. Finally, opFormat is used to format the decimal days value in the Duration format. (The input for the opFormat operator in the following advanced duration structure must ALWAYS be decimal days.) The result is 1 01:24:15 because 1455 is converted to the Duration format.

<FmtDurB desc="Format Duration Method B" readOnly="true" type="string" isRef="1"/>

<ref prec="0" refOp="opAssignId" deid="rawDur"/>

<ref prec="1" refOp="opUnitConversion" srcUnits="sec" destUnits="day"/>

<ref prec="2" refOp="opFormat" format="Duration"/>

</FmtDurB>

Useful attributes to know are isRef, prec, refOp, deid, and format. A useful element to know is ref.

Enron Date/Time

The following example uses two child elements to convert a date and time from the Enron format into the DateTime format. The first child element references the operation opTimeEnron and the data group elements rawDateE and rawTimeE to assign current values. The second child element then references the operation opFormat to output a date and time in DateTime format. In this case, the Enron date 120799.0 and time 031745.0 are converted to 07-Dec-99 03:17:45.

<DtEnron desc="Date Time Enron" readOnly="true" type="string" isRef="1">

<ref prec="0" refOp="opTimeEnron" deidDate="rawDateE" deidTime="rawTimeE"/>

<ref prec="1" refOp="opFormat" format="DateTime"/>

</DtEnron>

Useful attributes to know are isRef, prec, refOp, deidDate, deidTime, format, formatDate, and formatTime. A useful element to know is ref.

Seconds Date/Time

The following example uses two child elements to convert a date and time from seconds into the DateTime format. The first child element references the operation opTimeSeconds and the data group element rawTimeT to assign a current value. The second child element then references the operation opFormat to output a date and time in DateTime format. In this case, the seconds (1364736071) initialized for this data group have a start date of January 1, 1970, which results in a date of 31-Mar-13 13:21:11.

<DtTimeT desc="Date Time Seconds" readOnly="true" type="string" isRef="1">

<ref prec="0" refOp="opTimeSeconds" deidTime="rawTimeT"/>

<ref prec="1" refOp="opFormat" format="DateTime"/>

</DtTimeT>

Useful attributes to know are isRef, prec, refOp, deidTime, isUTC, baseTime, and format. A useful element to know is ref.

String Date/Time

The following example uses two child elements to convert a date and time from string date and time components. The first child element references the operation opTimeString and the data group elements rawDateS and rawTimeS to assign current values. The second child element then references the operation opFormat to output a date and time in DateTime format. In this case, the string date and time values initialized for this data group result in a date of 03-March-11 03:45:10.

<DtStr desc="Date Time String" readOnly="true" type="string" isRef="1">

<ref prec="0" refOp="opTimeString" deidDate="rawDateS" deidTime="rawTimeS"/>

<ref prec="1" refOp="opFormat" format="DateTime"/>

</DtStr>

Useful attributes to know are isRef, prec, refOp, deidDate, deidTime, and format. A useful element to know is ref.

Back to top

Let us know how we can improve this topic.

CygNet at weatherford.com

© 2020 Weatherford. All rights reserved.